var item;
$(document).ready(function(e){
	item = {
		title : 1,
		option : 0,
		answer : 1,
		vartext : 0,
		varnum : 0
	};
	$("#add-title").click(function(){
		item.title += 1;
		$("#title").append('<div class="list" id="title'+item.title+'"><span class="lab1 title-num">'+item.title+'</span><input type="text" class="title-input" name="title'+item.title+'" /></div>');	
		if(item.title == 2){
			$("#delete-title").fadeIn("normal");	
		}
	});
	$("#add-option").click(function(){
		if(item.option == 0){
			$("#option-title").css("color","#333");
			$("#option-title").html("选项");
			$("#delete-option").fadeIn("normal");
		}
		item.option += 1;
		$("#option").append('<div class="list" id="option'+item.option+'"><div class="lab">选项内容</div><input type="text" name="option'+item.option+'" class="answer-input"/><span class="lab1 ans-lab">对应题号</span><input type="text" class="answer-input1" name="option-key'+item.option+'" /></div>');
	});
	$("#add-answer").click(function(){
		item.answer += 1;
		$("#answer").append('<div class="list" id="answer'+item.answer+'"><div class="lab">答案内容</div><input type="text" name="answer'+item.answer+'" class="answer-input"/><span class="lab1 ans-lab">对应题号</span><input type="text" name="answer-key'+item.answer+'" class="answer-input1" /><br /><span class="lab1 ans-lab">答题空间(像素)</span><input type="text" name="answer-space'+item.answer+'" class="answer-input1" /><br /><span class="lab1 ans-lab">难度选择</span><span class="dif"><input type="radio" name="answer-difficulity'+item.answer+'"/>A<input type="radio" name="="answer-difficulity'+item.answer+'" />B<input type="radio" name="="answer-difficulity'+item.answer+'" />C<input type="radio" name="="answer-difficulity'+item.answer+'" />D</span></div>');
		if(item.answer == 2){
			$("#delete-answer").fadeIn("normal");	
		}
	});
	$("#add-var").click(function(){
		$("#var-title").css("color","#333");
		$("#var-title").html("变量");
		item.vartext = 1;
		$(this).fadeOut("normal");
		$("#delete-var").fadeIn("normal");
		$("#variable").append('<div class="list">'
                                +'<span class="lab1 ans-lab">变量名</span><input type="text" name="var-name" class="answer-input1" /><br />'
                                +'<span class="lab1 ans-lab">变量类型</span><span class="dif"><input type="radio" onclick="showVarnum()" name="var-type"/>数字<input type="radio" name="var-type" onclick="showVartext()" checked="check"/>文字</span>'
                           +' </div>'
                           +'<div class="box1 bor" id="vartext'+item.vartext+'">'
                                +'<a class="add1" href="javascript:void(0)" onclick="addVarText()">+</a>'
                                +'<div class="content1">'
                                   +'<div class="var-label">编辑文字</div>'
                                    +'<div class="var-text-box">'
                                        +'<span class="var-text-num">'+item.vartext+'</span><input type="text" name="var-text'+item.vartext+'" class="var-text-input" />'
                                    +'</div></div>'
									+'<a class="add1" href="javascript:void(0)" style="display:none;" id="delete-vartext" onclick="deleteVarText()">-</a>'
									+'</div>');
	});
	$("#delete-title").click(function(){
		$("#title"+item.title).remove();
		item.title -= 1;
		if(item.title == 1){
			$(this).fadeOut("normal");	
		}
	});
	$("#delete-option").click(function(){
		$("#option"+item.option).remove();
		item.option -= 1;
		if(item.option == 0){
			$(this).fadeOut("normal");	
		}
	});
	$("#delete-answer").click(function(){
		$("#answer"+item.answer).remove();
		item.answer -= 1;
		if(item.answer == 1){
			$(this).fadeOut("normal");	
		}
	});
	$("#delete-var").click(function(){
		$("#variable").empty();
		item.vartext = 0;
		item.varnum = 0;
		$("#var-title").css("color","#aaa");
		$("#var-title").html("变量(当前无变量)");
		$(this).hide();
		$("#add-var").show();
	});
});

function deleteList(type,id){
	$("#"+type+id).remove();
	switch (type){
		case "title":
			item.title -= 1;
			break;
		case "option":
			item.option -= 1;
			if(item.option == 0){
				$("#option-title").css("color","#aaa");
				$("#option-title").html("选项(当前无选项)");
			}
			break;
		case "answer":
			item.answer -= 1;
			break;
	}
};

function addVarText(){
	item.vartext += 1;
	$("#variable").append('<div class="box1 bor" id="vartext'+item.vartext+'">'
                                +'<div class="content1">'
                                   +'<div class="var-label">编辑文字</div>'
                                    +'<div class="var-text-box">'
                                        +'<span class="var-text-num">'+item.vartext+'</span><input type="text" name="var-text'+item.vartext+'" class="var-text-input" />'
                                    +'</div></div></div>');
	if(item.vartext == 2){
		$("#delete-vartext").show();	
	}
};

function deleteVarText(){
	$("#vartext"+item.vartext).remove();
	item.vartext -= 1;
	if(item.vartext == 1){
		$("#delete-vartext").hide();	
	}
};

function addVarNum(){
	item.varnum += 1;
	$("#variable").append('<div class="box1 bor" id="varnum'+item.varnum+'">'
							+'<div class="content1">'
								+'<div class="var-label">编辑数字</div>'
								+'<div class="var-text-box">'
									+'<span class="var-text-num">'+item.varnum+'</span><input type="text" name="var-num'+item.varnum+'" class="var-text-input" /><br />'
									+'<span class="var-num-lab0">数字范围</span><input type="text" name="var-num-range-l'+item.varnum+'" class="var-num-range" />~<input type="text" class="var-num-range" name="var-num-range-r'+item.varnum+'"/><span class="var-num-lab1">自动变化</span><input class="auto-change" name="var-num-auto'+item.varnum+'" type="checkbox" />'
								+'</div>'
							+'</div>'
						+'</div>');
	if(item.varnum == 2){
		$("#delete-varnum").fadeIn("normal");	
	}
}

function deleteVarNum(){
	$("#varnum"+item.varnum).remove();
	item.varnum -= 1;
	if(item.varnum == 1){
		$("#delete-varnum").hide();	
	}
};

function showVarnum(){
	if(item.varnum == 0){
		for( var i = 1;i <= item.vartext; i++){
			$("#vartext"+i).remove();	
		}
		item.vartext = 0;
		item.varnum = 1;
		$("#variable").append('<div class="box1 bor" id="varnum'+item.varnum+'">'
							+'<a class="add1" href="javascript:void(0)" id="add-varnum" onclick="addVarNum()">+</a>'
							+'<div class="content1">'
								+'<div class="var-label">编辑数字</div>'
								+'<div class="var-text-box">'
									+'<span class="var-text-num">'+item.varnum+'</span><input type="text" name="var-num'+item.varnum+'" class="var-text-input" /><br />'
									+'<span class="var-num-lab0">数字范围</span><input type="text" name="var-num-range-l'+item.varnum+'" class="var-num-range" />~<input type="text" class="var-num-range" name="var-num-range-r'+item.varnum+'"/><span class="var-num-lab1">自动变化</span><input class="auto-change" name="var-num-auto'+item.varnum+'" type="checkbox" />'
								+'</div>'
							+'</div>'
							+'<a class="add1" href="javascript:void(0)" style="display:none;" id="delete-varnum" onclick="deleteVarNum()">-</a>'
						+'</div>');
	}
};

function showVartext(){
	if(item.vartext == 0){
		for( var i = 1;i <= item.varnum; i++){
			$("#varnum"+i).remove();	
		}
		item.varnum = 0;
		item.vartext = 1;
		$("#variable").append('<div class="box1 bor" id="vartext'+item.vartext+'">'
                                +'<a class="add1" href="javascript:void(0)" onclick="addVarText()">+</a>'
                                +'<div class="content1">'
                                   +'<div class="var-label">编辑文字</div>'
                                    +'<div class="var-text-box">'
                                        +'<span class="var-text-num">'+item.vartext+'</span><input type="text" name="var-text'+item.vartext+'" class="var-text-input" />'
                                    +'</div></div>'
									+'<a class="add1" href="javascript:void(0)" style="display:none;" id="delete-vartext" onclick="deleteVarText()">-</a>'
									+'</div>');
	}
};
